package examtest;

import java.util.concurrent.TimeUnit;

//volidate可见性测试
//没想出来其他实现方式，最后采用老师的例子
public class homewoek3_1 {
    volatile boolean b = true;

    void f1() {
        System.out.println("start");
        while(b){
            //会在b的值变化后停止

        }
        System.out.println("end");
    }

    public static void main(String[] args) {
        homewoek3_1 homewoek3_1 = new homewoek3_1();
        new Thread(new Runnable() {
            @Override
            public void run() {
                homewoek3_1.f1();
            }
        }).start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        homewoek3_1.b = false;

        System.out.println("set b to false..");
    }
}
